//
//  GenderViewController.m
//  IStar-Project
//
//  Created by RyanLin on 13/8/2015.
//  Copyright (c) 2015年 RyanLin. All rights reserved.
//

#import "GenderViewController.h"
//#import "IStarModifyUserInfo.h"

@interface GenderViewController ()

@end



@implementation GenderViewController


@synthesize select;
@synthesize cancelButton;
@synthesize submitButton;
@synthesize picker;

@synthesize motherLabel;
@synthesize motherWindow;

@synthesize originalGender;
@synthesize motherImg;
-(void)dealloc
{
    select=NULL;
    motherLabel=NULL;
    motherWindow=NULL;
    motherImg=NULL;
}
-(void)viewWillAppear:(BOOL)animated
{
    if (originalGender==NULL||[originalGender isEqualToString:@"0"])
    {
        [picker selectRow:0 inComponent:0 animated:NO];
    }
    else
    {
        //originalRoundString=[originalRoundString substringToIndex:originalRoundString.length];
        //originalGender=[originalRoundString intValue];
        if([originalGender isEqualToString:@"女孩"])
        {
            [picker selectRow:0 inComponent:0 animated:NO];
            select=@"0";
        }
        else
        {
            [picker selectRow:1 inComponent:0 animated:NO];
            select=@"1";
        }
        
    }
    
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setFrame:[UIScreen mainScreen].bounds];
    
    
//    UIView *backgroundView = [[UIView alloc] initWithFrame:[[UIApplication sharedApplication] keyWindow].frame];
//    backgroundView.backgroundColor = [UIColor blackColor];
//    backgroundView.alpha = 0.4;
//    [self.view addSubview:backgroundView];

    picker.dataSource=self;
    picker.delegate=self;
    
    [submitButton addTarget:self action:@selector(submitAction) forControlEvents:UIControlEventTouchDown];
    [cancelButton addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchDown];

    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    if(self.view.window==nil)
    {
        self.view=nil;
    }
}
-(void)submitAction
{
    
    
    
    
    if (select==nil){select=@"0";}
    //[IStarModifyUserInfo ModifyGender:select];
    if ([select isEqual:@"0"])
    {
        motherLabel.text=@"女孩";
        if(motherImg!=NULL)
        {
            motherImg.image=[UIImage imageNamed:@"avater_girl.png"];
        }
        //NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
        //[userDefaults setValue:@"女" forKey:@"gender"];
    }
    else
    {
        motherLabel.text=@"男孩";
        if(motherImg!=NULL)
        {
            motherImg.image=[UIImage imageNamed:@"avater_boy.png"];
        }        
        //NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
        //[userDefaults setValue:@"男" forKey:@"gender"];
    }
    
    self.motherWindow.hidden=YES;

}
-(void)cancelAction
{
    self.motherWindow.hidden=YES;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
//返回显示的列数
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
//返回当前列显示的行数
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    
    return 2;
    
}

#pragma mark Picker Delegate Methods

//返回当前行的内容,此处是将数组中数值添加到滚动的那个显示栏上
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (row==0)
    {
        return @"女孩";
    }
    else
    {
        return @"男孩";

    }
    
}
// 当用户选中UIPickerViewDataSource中指定列和列表项时激发该方法
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    select=[NSString stringWithFormat:@"%d",row];
}
@end
